package com.nhn.ssi.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import org.apache.struts2.ServletActionContext;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.ibatis.sqlmap.client.SqlMapClient;
import com.nhn.ssi.bo.TestBo;
import com.opensymphony.xwork2.ActionSupport;

public class LoginAction extends ActionSupport {
	private static final long serialVersionUID = -357905587630066069L;
	String username;
	String password;
	TestBo testBo  ;

	public TestBo getTestBo() {
		return testBo;
	}

	public void setTestBo(TestBo testBo) {
		this.testBo = testBo;
	}
	java.util.List<Object> list;

	@SuppressWarnings("unchecked")
	public String login() throws Exception {
//		// 通过spring注入获得sqlmap
//		BeanFactory factory = new ClassPathXmlApplicationContext(
//				"*.xml");
//
//		// 得到UserService具体实现，用于操作业务逻辑
//		testBo = (TestBo) factory.getBean("testBo");
		
		
		
		HttpServletRequest request = ServletActionContext.getRequest();
		HttpSession session = request.getSession();
		System.out.print("dnidayda das ");
		boolean b = testBo.login(username, password);
		if (b) {
			// 登陆成功，session中设置登陆状态
			session.setAttribute("username", username);
//			list = testBo.getAllUserList();
//			return SUCCESS;
			return "findnhn";
		} else
			return "failure";
	}

	public String quit() throws Exception {
		HttpServletRequest request = ServletActionContext.getRequest();
		HttpSession session = request.getSession();
		System.out.print("quit zhe system!!! ");
		session.removeAttribute("username");
		return SUCCESS;
	}

	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public java.util.List<Object> getList() {
		return list;
	}

	public void setList(java.util.List<Object> list) {
		this.list = list;
	}

}
